<template>
  <div class="p-2">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="mb-[10px]">
        <el-card shadow="hover">
          <el-form ref="queryFormRef" :model="queryParams" :inline="true">
            <el-form-item label="项目名" prop="projectName">
              <el-input v-model="queryParams.projectName" placeholder="请输入项目名" clearable @keyup.enter="handleQuery" />
            </el-form-item>
            <el-form-item label="负责人" prop="owner">
              <!-- <el-input v-model="queryParams.owner" placeholder="请输入负责人" clearable @keyup.enter="handleQuery" /> -->
              <el-select v-model="queryParams.owner" filterable placeholder="请选择" clearable>
                <el-option
                  v-for="([key, value], index) in Object.entries(postOptions)"
                  :key="key"
                  :label="value"
                  :value="key"
                  @keyup.enter="handleQuery"
                >
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
        </el-card>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" plain icon="Plus" @click="handleAdd" v-hasPermi="['pm:project:add']">新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="warning" plain icon="Download" @click="handleExport" v-hasPermi="['pm:project:export']">导出</el-button>
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" :data="projectList" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <!-- <el-table-column label="主键" align="center" prop="id" v-if="true" /> -->
        <el-table-column v-if="columns[0].visible" label="项目编号" align="center" prop="projectCode" :show-overflow-tooltip="true" width="300">
          <template #default="scope">
            <el-tag :style="{ color: scope.row.classStyle }">{{ scope.row.projectCode }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[1].visible" label="项目名" align="center" prop="projectName" :show-overflow-tooltip="true" width="300">
          <template #default="scope">
            <el-tag :style="{ color: scope.row.classStyle }">{{ scope.row.projectName }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[2].visible" label="负责人" align="center" prop="ownerName" />
        <el-table-column v-if="columns[3].visible" label="排序" align="center" prop="projectSort" />
        <el-table-column v-if="columns[4].visible" label="关联人员" align="center" prop="relatedUsers" />
        <el-table-column v-if="columns[5].visible" label="状态" align="center" prop="status">
          <template #default="scope">
            <span>{{ scope.row.status == 0 ? '正常' : '禁用' }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[6].visible" label="创建部门" align="center" prop="createDeptName" />
        <el-table-column v-if="columns[7].visible" label="创建者" align="center" prop="createByName" />
        <el-table-column v-if="columns[8].visible" label="创建时间" align="center" prop="createTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[9].visible" label="修改者" align="center" prop="updateByName" />
        <el-table-column v-if="columns[10].visible" label="创建时间" align="center" prop="updateTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
          </template>
        </el-table-column>
        <!-- 显示版本号 -->
        <!-- <el-table-colimn>
          <el-table-column v-if="columns[12].visible" label="版本号" align="center" prop="version" />
        </el-table-colimn> -->
        <el-table-column v-if="columns[11].visible" label="备注" align="center" prop="remark" :show-overflow-tooltip="true" width="300" />
        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="320px">
          <template #default="scope">
            <el-button link type="primary" icon="View" @click="handView(scope.row)">预览</el-button>

            <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['pm:project:edit']">修改</el-button>

            <el-button link type="primary" icon="Plus" @click="addMilestoneBtn(scope.row)">新增小目标</el-button>

            <el-button link type="primary" icon="Plus" @click="addVersionBtn(scope.row)">新增版本号</el-button>

            <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['pm:project:remove']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>

      <pagination v-show="total > 0" :total="total" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" @pagination="getList" />
    </el-card>
    <!-- 添加或修改项目对话框 -->
    <el-dialog :title="dialog.title" v-model="dialog.visible" append-to-body>
      <el-form ref="projectFormRef" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目编号">
              <el-input v-model="form.projectCode" placeholder="请输入大写字母数字和_" @input="handleMilestoneSortInput" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目名" prop="projectName">
              <el-input v-model="form.projectName" placeholder="请输入项目名" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="负责人">
              <el-select v-model="form.owner" filterable placeholder="请选择">
                <el-option v-for="([key, value], index) in Object.entries(postOptions)" :key="key" :label="value" :value="key"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排序" prop="projectSort">
              <el-input v-model="form.projectSort" placeholder="请输入数字排序" type="number" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="关联人员">
              <el-select v-model="form.relatedUsers" filterable multiple placeholder="请选择">
                <el-option v-for="([key, value], index) in Object.entries(postOptions)" :key="key" :label="value" :value="key"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态">
              <el-radio-group v-model="form.status">
                <el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="项目颜色">
              <el-select v-model="form.classStyle" placeholder="请选择颜色">
                <el-option v-for="dict in pm_color" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 预览项目对话框 -->
    <el-dialog :title="dialog.title" v-model="dialog.viewVisible" append-to-body>
      <el-form ref="projectFormRef" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="项目编号" prop="projectCode">
              <el-input v-model="form.projectCode" placeholder="请输入项目编号" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="项目名" prop="projectName">
              <el-input v-model="form.projectName" placeholder="请输入项目名" readonly />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="负责人">
              <el-select v-model="form.owner" filterable placeholder="请选择" disabled>
                <el-option v-for="([key, value], index) in Object.entries(postOptions)" :key="key" :label="value" :value="key"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="排序" prop="projectSort">
              <el-input v-model="form.projectSort" placeholder="请输入排序" readonly />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="关联人员">
              <el-select v-model="form.relatedUsers" filterable multiple placeholder="请选择" disabled>
                <el-option v-for="([key, value], index) in Object.entries(postOptions)" :key="key" :label="value" :value="key"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态">
              <el-radio-group v-model="form.status" disabled>
                <el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="创建者" prop="projectCode">
              <el-input v-model="form.createByName" placeholder="请输入创建者" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="创建时间" prop="projectCode">
              <el-input v-model="form.createTime" placeholder="请输入创建时间" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="修改者">
              <el-input v-model="form.updateByName" placeholder="修改者" readonly />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="修改时间">
              <el-input v-model="form.updateTime" placeholder="请输入创建时间" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="创建部门" prop="projectCode">
              <el-input v-model="form.createDeptName" placeholder="请输入创建部门" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <!-- <el-row>
          <el-col :span="12">
            <el-form-item label="版本号">
              <el-select v-model="form.version" filterable placeholder="请选择" disabled>
                <el-option v-for="([key, value], index) in Object.entries(version)" :key="key" :label="value" :value="key"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row> -->
        <el-form-item label="备注">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" readonly></el-input>
        </el-form-item>
      </el-form>
    </el-dialog>

    <!-- 添加或修改小目标对话框 -->
    <el-dialog :title="dialog.title" v-model="milestoneisible" append-to-body>
      <el-form ref="milestoneFormRef" :model="milform" label-width="80px" :rules="milestoneRules">
        <el-row>
          <el-col :span="12">
            <el-form-item label="小目标名" prop="milestoneName">
              <el-input v-model="milform.milestoneName" placeholder="请输入小目标名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关联人员">
              <el-select v-model="milform.relatedUsers" filterable multiple placeholder="请选择">
                <el-option v-for="([key, value], index) in Object.entries(postOptions)" :key="key" :label="value" :value="key"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="排序" prop="milestoneSort">
              <el-input v-model="milform.milestoneSort" placeholder="请输入排序" type="number" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="状态">
              <el-radio-group v-model="milform.status">
                <el-radio v-for="dict in sys_normal_disable" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注">
          <el-input v-model="milform.remark" type="textarea" placeholder="请输入内容"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="milestoneSubmitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>

    <!-- 添加版本号对话框 -->
    <el-dialog :title="dialog.title" v-model="versionisible" append-to-body="true">
      <el-form ref="versionFormRef" :model="version" label-width="80px" :rules="versionRules">
        <el-row>
          <!-- 新版本号下拉框 -->
          <el-col :span="12">
            <!-- 版本号 -->
            <el-form-item label="版本号">
              <div class="version-selectors">
                <!-- 主版本号 -->
                <el-select v-model="taskForm.majorVersion" filterable placeholder="主版本号" class="version-selector">
                  <el-option v-for="num in versionNumbers" :key="num" :label="num" :value="num"></el-option>
                </el-select>
                <span class="version-separator">.</span>
                <!-- 次版本号 -->
                <el-select v-model="taskForm.minorVersion" filterable placeholder="次版本号" class="version-selector">
                  <el-option v-for="num in versionNumbers" :key="num" :label="num" :value="num"></el-option>
                </el-select>
                <span class="version-separator">.</span>
                <!-- 修订号 -->
                <el-select v-model="taskForm.patchVersion" filterable placeholder="修订号" class="version-selector">
                  <el-option v-for="num in versionNumbers" :key="num" :label="num" :value="num"></el-option>
                </el-select>
              </div>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="关联人员">
              <el-select v-model="version.relatedUsers" filterable multiple placeholder="请选择">
                <el-option v-for="([key, value], index) in Object.entries(postOptions)" :key="key" :label="value" :value="key"> </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="排序" prop="versionSort">
              <el-input v-model="version.versionSort" placeholder="请输入排序" type="number" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="发布状态">
              <el-radio-group v-model="version.status">
                <el-radio v-for="dict in pm_project_release" :key="dict.value" :value="dict.value">{{ dict.label }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="备注">
          <el-input v-model="version.remark" type="textarea" placeholder="请输入内容"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <div class="dialog-footer">
          <el-button :loading="buttonLoading" type="primary" @click="milestoneSubmitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script setup name="Project" lang="ts">
import { listProject, getProject, delProject, addProject, updateProject } from '@/api/pm/project/index';
import { ProjectVO, ProjectQuery, ProjectForm } from '@/api/pm/project/types';
import api from '@/api/system/user/index';
import { getUserProfile } from '@/api/system/user/index';
import { UserVO } from '@/api/system/user/types';
import { addMilestone } from '@/api/pm/milestone/index';
import { addVersion } from '@/api/pm/version/index';
const { proxy } = getCurrentInstance() as ComponentInternalInstance;
import { MilestoneVO, MilestoneQuery, MilestoneForm } from '@/api/pm/milestone/types';
import { VersionVO, VersionQuery, VersionForm } from '@/api/pm/version/types';
const { sys_normal_disable, sys_user_sex, pm_project_release } = toRefs<any>(
  proxy?.useDict('sys_normal_disable', 'sys_user_sex', 'pm_project_release')
);
const { pm_color } = toRefs<any>(proxy?.useDict('pm_color'));
const state = ref<State>({
  user: {}
});
interface State {
  user: Partial<UserVO>;
}

const Milestone_id = ref();
const Version_id = ref();
const projectID = ref();
const postOptions = ref([]);
const projectList = ref<ProjectVO[]>([]);
const buttonLoading = ref(false);
const loading = ref(true);
const showSearch = ref(false);
const ids = ref<Array<string | number>>([]);
const single = ref(true);
const multiple = ref(true);
const total = ref(0);
const milestoneisible = ref(false);
const queryFormRef = ref<ElFormInstance>();
const projectFormRef = ref<ElFormInstance>();
const milestoneFormRef = ref<ElFormInstance>();
const versionisible = ref(false);
const versionFormRef = ref<ElFormInstance>();
const dialog = reactive<DialogOption>({
  visible: false,
  title: '',
  viewVisible: false
});
const columns = ref<FieldOption[]>([
  { key: 0, label: `项目编号`, visible: true, children: [] },
  { key: 1, label: `项目名`, visible: true, children: [] },
  { key: 2, label: `负责人`, visible: true, children: [] },
  { key: 3, label: `排序`, visible: false, children: [] },
  { key: 4, label: `关联人员`, visible: false, children: [] },
  { key: 5, label: `状态`, visible: true, children: [] },
  { key: 6, label: `创建部门`, visible: false, children: [] },
  { key: 7, label: `创建者`, visible: true, children: [] },
  { key: 8, label: `创建时间`, visible: false, children: [] },
  { key: 9, label: `修改者`, visible: false, children: [] },
  { key: 10, label: `修改时间`, visible: false, children: [] },
  { key: 11, label: `备注`, visible: true, children: [] }
]);

const milform = ref({
  id: undefined,
  tenantId: undefined,
  projectId: undefined,
  milestoneName: undefined,
  milestoneSort: undefined,
  versionName: undefined,
  versionSort: undefined,
  relatedUsers: undefined,
  status: '0',
  remark: undefined,
  createByName: undefined,
  updateByName: undefined,
  createDeptName: undefined
});
const version = ref({
  id: undefined,
  tenantId: undefined,
  projectId: undefined,
  versionName: undefined,
  versionSort: undefined,
  relatedUsers: undefined,
  status: '0',
  remark: undefined,
  createByName: undefined,
  updateByName: undefined,
  createDeptName: undefined
});
const milestoneRules = ref({
  milestoneName: [{ required: true, message: '小目标名不能为空', trigger: 'blur' }],
  status: [{ required: true, message: '状态不能为空', trigger: 'change' }]
});
const versionRules = ref({
  versionName: [{ required: true, message: '版本号不能为空', trigger: 'blur' }],
  status: [{ required: true, message: '发布状态不能为空', trigger: 'change' }]
});
const initFormData: ProjectForm = {
  id: undefined,
  projectCode: undefined,
  projectName: undefined,
  owner: undefined,
  projectSort: undefined,
  relatedUsers: undefined,
  status: '0',
  classStyle: undefined,
  remark: undefined,
  createByName: undefined,
  updateByName: undefined,
  createDeptName: undefined,
  version: undefined
};
const data = reactive<PageData<ProjectForm, ProjectQuery>>({
  form: { ...initFormData },
  queryParams: {
    pageNum: 1,
    pageSize: 50,
    projectCode: undefined,
    projectName: undefined,
    owner: undefined,
    relatedUsers: undefined,
    status: undefined,
    version: undefined,
    params: {}
  },
  rules: {
    projectCode: [{ required: true, message: '只能输入大写字母数字和_', trigger: 'change' }],
    projectName: [{ required: true, message: '项目名不能为空', trigger: 'blur' }],
    owner: [{ required: true, message: '负责人不能为空', trigger: 'blur' }],
    status: [{ required: true, message: '状态不能为空', trigger: 'change' }]
    // version: [{ required: true, message: '版本号不能为空', trigger: 'change' }]
  }
});
function handleMilestoneSortInput(value) {
  form.value.projectCode = value.replace(/[^A-Z0-9-]/g, '');
}
function handleVersionSortInput(value) {
  form.value.projectCode = value.replace(/[^A-Z0-9-]/g, '');
}
const { queryParams, form, rules } = toRefs(data);

/** 查询项目列表 */
const getList = async () => {
  loading.value = true;
  queryParams.value.isAsc = 'desc';
  queryParams.value.orderByColumn = 'id';
  const res = await listProject(queryParams.value);
  projectList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};

/** 取消按钮 */
const cancel = () => {
  reset();
  dialog.visible = false;
  milestoneisible.value = false;
};

/** 表单重置 */
const reset = () => {
  form.value = { ...initFormData };
  milform.value = {
    id: undefined,
    tenantId: undefined,
    projectId: undefined,
    milestoneName: undefined,
    milestoneSort: undefined,
    versionName: undefined,
    versionSort: undefined,
    relatedUsers: undefined,
    status: '0',
    remark: undefined,
    createByName: undefined,
    updateByName: undefined,
    createDeptName: undefined
  };
  projectFormRef.value?.resetFields();
};

/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.value.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  queryFormRef.value?.resetFields();
  handleQuery();
};

/** 多选框选中数据 */
const handleSelectionChange = (selection: ProjectVO[]) => {
  ids.value = selection.map((item) => item.id);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
};

/** 新增按钮操作 */
const handleAdd = async () => {
  reset();
  dialog.visible = true;
  dialog.title = '添加项目';
  form.value.owner = projectID.value;
  form.value.projectSort = total.value + 1;
  // 获取目标关联人
  // const data1 = await api.affiliatePperson('user');
  // postOptions.value = data1.data;
};

/** 预览按钮操作 */
const handView = async (row?: ProjectVO) => {
  reset();
  const data1 = await api.affiliatePperson('user');
  postOptions.value = data1.data;
  const _id = row?.id || ids.value[0];
  const res = await getProject(_id);
  console.log('预览内容', res.data);
  res.data.relatedUsers = JSON.parse(res.data.relatedUsers);
  Object.assign(form.value, res.data);

  dialog.viewVisible = true;
  dialog.title = '预览项目';
};
/** 修改按钮操作 */
const handleUpdate = async (row?: ProjectVO) => {
  reset();
  const _id = row?.id || ids.value[0];
  const res = await getProject(_id);
  res.data.relatedUsers = JSON.parse(res.data.relatedUsers);
  // res.data.owner = JSON.parse(res.data.owner);
  Object.assign(form.value, res.data);
  const data1 = await api.affiliatePperson('user');
  postOptions.value = data1.data;
  dialog.visible = true;
  dialog.title = '修改项目';
};

/** 新增小目标按钮操作 */
const addMilestoneBtn = async (row?: ProjectVO) => {
  reset();
  const _id = row?.id || ids.value[0];
  const res = await getProject(_id);
  console.log('项目id', res);
  milform.value.projectId = res.data.id;
  milestoneisible.value = true;
  dialog.title = '新增小目标';
};

/** 新增版本号按钮操作 */
const addVersionBtn = async (row?: ProjectVO) => {
  reset();
  const _id = row?.id || ids.value[0];
  const res = await getProject(_id);
  console.log('项目id', res);
  milform.value.projectId = res.data.id;
  versionisible.value = true;
  dialog.title = '新增版本号';
};

/** 提交按钮 */
const submitForm = () => {
  projectFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      form.value.relatedUsers = JSON.stringify(form.value.relatedUsers);
      if (form.value.id) {
        await updateProject(form.value).finally(() => (buttonLoading.value = false));
      } else {
        await addProject(form.value).finally(() => (buttonLoading.value = false));
      }
      proxy?.$modal.msgSuccess('操作成功');
      dialog.visible = false;
      await getList();
    }
  });
};
/** 提交小目标按钮 */
const milestoneSubmitForm = async () => {
  milestoneFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      milform.value.relatedUsers = JSON.stringify(milform.value.relatedUsers);

      await addMilestone(milform.value).finally(() => (buttonLoading.value = false));
      proxy?.$modal.msgSuccess('操作成功');
      milestoneisible.value = false;
    }
  });
};
/** 提交版本号按钮 */
const versoinSubmitForm = async () => {
  versionFormRef.value?.validate(async (valid: boolean) => {
    if (valid) {
      buttonLoading.value = true;
      milform.value.relatedUsers = JSON.stringify(milform.value.relatedUsers);

      await addVersion(milform.value).finally(() => (buttonLoading.value = false));
      proxy?.$modal.msgSuccess('操作成功');
      versionisible.value = false;
    }
  });
};
/** 删除按钮操作 */
const handleDelete = async (row?: ProjectVO) => {
  const _ids = row?.id || ids.value;
  await proxy?.$modal.confirm('是否确认删除项目编号为"' + _ids + '"的数据项？').finally(() => (loading.value = false));
  await delProject(_ids);
  proxy?.$modal.msgSuccess('删除成功');
  await getList();
};

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download(
    'pm/project/export',
    {
      ...queryParams.value
    },
    `project_${new Date().getTime()}.xlsx`
  );
};

const allList = async () => {
  const data1 = await api.affiliatePperson('user');
  postOptions.value = data1.data;
};
const getUser = async () => {
  const res = await getUserProfile();
  state.value.user = res.data.user;
  projectID.value = state.value.user.userId;
  // console.log("用户信息", state.value.user)
};
onMounted(() => {
  getList();
  allList();
  getUser();
});
//表单数据
const taskForm = ref({
  majorVersion: null, //主版本号
  minorVersion: null, //次版本号
  patchVersion: null //修订号
});
//版本号选择
const versionNumbers = ref([0, 1, 2, 3, 4, 5, 6, 7, 8, 9]); //可根据需求调整
</script>
<style>
.version-selectors {
  display: flex;
  align-items: center;
}

.version-selector {
  width: 109px; /* 每个下拉框宽度为 80px */
}

.version-separator {
  margin: 0 8px;
  font-size: 16px;
  font-weight: bold;
}
</style>
